//
//  VoiceTypeController.swift
//  newShaohuoRen
//
//  Created by hujinbiao on 2018/3/24.
//  Copyright © 2018年 hujinbiao. All rights reserved.
//

import UIKit

protocol VoiceTypeControllerDelegate {
    func voiceTypeController(sex:String)
}

class VoiceTypeController: UITableViewController {
    
    var selIndex : IndexPath!
    
    var sexStr : String!
    
    var delegate : VoiceTypeControllerDelegate?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = "语音模式"
        
        if sexStr == "男声" {
            selIndex = IndexPath(row: 0, section: 0)
        }else {
            selIndex = IndexPath(row: 1, section: 0)
        }
        tableView.selectRow(at: selIndex, animated: true, scrollPosition: UITableViewScrollPosition.top)
        let indexPath = tableView.indexPathForSelectedRow
        let cell = tableView.cellForRow(at: indexPath!)
        cell?.accessoryType = .checkmark
    }
}

extension VoiceTypeController {
    
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 20
    }
    
    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.001
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        if selIndex != nil {
            let cell = tableView.cellForRow(at: selIndex)
            cell?.accessoryType = .none
        }
        
        let cell = tableView.cellForRow(at: indexPath)
        cell?.accessoryType = .checkmark
        
        selIndex = indexPath
        
        if indexPath.row == 0 {
            delegate?.voiceTypeController(sex: "男声")
            UserNotificationSettingModel.sharedInstance.is_voice_sex = "new_order"
        }else{
            delegate?.voiceTypeController(sex: "女声")
            UserNotificationSettingModel.sharedInstance.is_voice_sex = "new_order_fm"
        }
        navigationController?.popViewController(animated: true)
    }
}
